#!/bin/bash

NAME="gmtm"
GROUP="graphics"
RELEASE="0"
LICENSE="GPL"

DESCRIPTIONPAK="description-pak"
MAINTAINERPAK="maintainer-pak"

checkinstall=`which checkinstall`
fakeroot=`which fakeroot`

if [ ! -x "$checkinstall" ] ; then
	echo "Error: checkinstall not found"
	exit 1
fi

if [ ! -x "$fakeroot" ] ; then
	echo "Error: fakeroot not found"
	exit 1
fi

version=`grep '#define VERSION' src/version.h |awk '{print $3}'`
if [ -z "$version" ] ; then
	echo "Cannot determine version"
	exit 1
fi

if [ ! -r $MAINTAINERPAK ] ; then
	echo "Package's maintainer (eg: John Doe <john@example.com>) :"
	read maintainer
	echo "$maintainer" > $MAINTAINERPAK
fi

if [ ! -r $DESCRIPTIONPAK ] ; then
	echo "Google Maps™ Tileset Maker
Split an image to tiles at different zoom levels. The generated tilesets are
intended to be used with Google Maps™ mapping service." > $DESCRIPTIONPAK
fi

maintainer=`head -n 1 $MAINTAINERPAK | sed 's/</\\\\</g;s/>/\\\\>/g'`

$fakeroot $checkinstall --install=no --backup=no --nodoc \
	--maintainer="$maintainer" --pkgversion="$version" --pkgname="$NAME" \
	--pkgrelease="$RELEASE" --pkglicense="$LICENSE" --pkggroup="$GROUP" \
	$* || exit 1

exit 0

